package com.zeus;

/**
 * Created by Administrator on 2015/10/2.
 */
import org.junit.Test;

import java.io.*;

public class FileOp {

    @Test
    public void testPath(){
        String path = "D:/a/1.txt";
        File file = new File(path);
        if(!file.exists()){
            file.mkdirs();
        }


    }

    @Test
    public void copyFile() throws Exception{
        String inPath = "D:/abc/bcd/1.txt";
        String outPath = "D:/a/1.txt";
        File outFile = new File(outPath);
        if(!outFile.getParentFile().exists()){
            outFile.getParentFile().mkdirs();
        }
        InputStream in = new FileInputStream(inPath);
        OutputStream out = new FileOutputStream(outFile);
        byte[] buf = new byte[1];
        while(in.read(buf)!= -1){
            out.write(buf);
        }
    }

    @Test
    public void createPath(){
        String path = "D:/a/1.txt";
        File f = new File(path);
        System.out.println(f.getPath());
        System.out.println(f.getName());
        System.out.println(f.getParent());
    }

    @Test
    public void getClassPath(){
        System.out.println(this.getClass().getResource("").getPath());
        //能获取类路径 如果传入空字符串作为参数
        //如果传入"/",能获取类的根路径
        //System.out.println(this.getClass().getClassLoader().getResource("/").getPath());error
        System.out.println(this.getClass().getClassLoader().getResource("").getPath());
        //这个获取根路径

    }


}
